/*
 * @Author: zyp yangpeng.zhang@fts.aero
 * @Date: 2024-06-04 10:02:53
 * @LastEditors: zyp yangpeng.zhang@fts.aero
 * @LastEditTime: 2024-07-05 17:39:00
 * @FilePath: \vue3-dynamic-module\src\main.ts
 * @Description: 程式描述
 */
// i18n
import { createI18n } from 'vue-i18n';
import messages from '@intlify/vite-plugin-vue-i18n/messages';
// vue router
import router from '@/router/index';
// pinia
import store from '@/store';
import App from './App.vue';
// import 'vant/es/notify/style';
// import 'vant/es/toast/style';
import '@/assets/styles/index.scss';
import Vconsole from 'vconsole';
import 'lib-flexible/flexible.js'
import ModulesManager from '@/modules/modulesManager';
import { configWindowGlobalThis } from '@/modules/umd';
import config from '../public/config.json';
// 引入模块后自动生效
import '@vant/touch-emulator';
import { Lazyload } from 'vant';

(window as any).config = config;

// if (import.meta.env.MODE === 'development') {
//   new Vconsole();
// }

const i18n = createI18n({
  locale: 'en',
  messages,
});

const app = createApp(App);

// 注册时可以配置额外的选项
app.use(Lazyload, {
  lazyComponent: true,
  loading: new URL('./assets/lazy/loading.svg', import.meta.url).href,
  error: new URL('./assets/lazy/error.png', import.meta.url).href,
});

app.use(store).use(i18n);

configWindowGlobalThis();

// 创建ModulesManager实例并等待模块加载完成
const modulesManager = new ModulesManager(app);
modulesManager.importModules().finally(()=>{
  app.config.globalProperties.$modulesManager = modulesManager;
  app.use(router);
  app.mount('#app');
});
